package com.cn.mobileproject.view.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.cn.mobileproject.R;
import com.cn.mobileproject.bean.Message;
import com.cn.mobileproject.bean.Project;
import com.cn.mobileproject.data.GlobalValue;

public class MessageAdapter extends BaseAdapter{
protected Context mContext;
	
	public MessageAdapter(Context context){
		mContext = context;
	}
	
	protected ArrayList<Message> mList ;
	
	@Override
	public int getCount() {
		if(mList==null) return 0;
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}
	
	class ViewHolder{
		TextView contentText;
		TextView tiemText;
		TextView sourceText;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if(convertView == null){
			convertView = LayoutInflater.from(mContext).inflate(R.layout.message_item, null);
			holder = new ViewHolder();
			holder.contentText =(TextView) convertView.findViewById(R.id.message_item_text_content);
			holder.tiemText =(TextView) convertView.findViewById(R.id.message_item_text_time);
			holder.sourceText =(TextView) convertView.findViewById(R.id.message_item_text_source);
			convertView.setTag(holder);
		}
		else{
			holder = (ViewHolder) convertView.getTag();
		}
		if(position>mList.size()||holder==null) return convertView;
		Message msg = mList.get(position);
		if(msg!=null){
			holder.contentText.setText(msg.messageContent);
			holder.sourceText.setText(msg.messageSource);
			holder.tiemText.setText(msg.sendDate);
		}
		return convertView;
	}

	public ArrayList<Message> getList() {
		return mList;
	}

	public void setList(ArrayList<Message> list){
		if(mList==null){
			mList = new ArrayList<Message>();
		}
		mList.clear();
		if(list!=null){
			mList.addAll(list);
		}
	}
}
